package com.design.blog.controller;

import com.design.blog.model.vo.CommentParams;
import com.design.blog.model.R;
import com.design.blog.service.impl.CommentServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author hxg
 * @version 1.0
 * @date 2022/2/28 23:15
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private CommentServiceImpl commentService;

    @GetMapping("/article/{id}")
    public R getArticleComment(@PathVariable("id") Long id){
        return R.success(commentService.getArticleCommentList(id));
    }
    @PostMapping("/article/publishComment")
    public R publishComment(@RequestHeader("Authorization") String token,
                            @RequestBody CommentParams commentParams){
        if (token == null) {
            return R.fail(401, "请先登录账户");
        }
        return commentService.comment(token,commentParams);
    }
}
